﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:COL_FEESFREE
	/// </summary>
	public partial class COL_FEESFREE : BaseDAL<GSLMS.Entity.TB_COL_FEESFREE>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public COL_FEESFREE()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_COL_FEESFREE model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_ACTINT", model.ACTINT),
								new OracleParameter("P_ACTMANAGE", model.ACTMANAGE),
								new OracleParameter("P_ACTCAPITAL", model.ACTCAPITAL),
								new OracleParameter("P_LEFTCAPITAL", model.LEFTCAPITAL),
								new OracleParameter("P_ACCPAYDATE", model.ACCPAYDATE),
								new OracleParameter("P_REDCAPITAL", model.REDCAPITAL),
								new OracleParameter("P_REDINT", model.REDINT),
								new OracleParameter("P_REDMANAGE", model.REDMANAGE),
								new OracleParameter("P_REDDELAYINT", model.REDDELAYINT),
								new OracleParameter("P_REDFAILCHARGE", model.REDFAILCHARGE),
								new OracleParameter("P_REDDELAYAMT", model.REDDELAYAMT),
								new OracleParameter("P_REDDONFEE", model.REDDONFEE),
								new OracleParameter("P_REDEXTFEE", model.REDEXTFEE),
								new OracleParameter("P_REDCHARGEFEE", model.REDCHARGEFEE),
								new OracleParameter("P_TOTALREDUCE", model.TOTALREDUCE),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_APPLYBY", model.APPLYBY),
								new OracleParameter("P_APPLYDATE", model.APPLYDATE),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_CANCELBY", model.CANCELBY),
								new OracleParameter("P_CANCELTIME", model.CANCELTIME),
								new OracleParameter("P_CANCELREASON", model.CANCELREASON),
								new OracleParameter("P_TOUSER", model.TOUSER),
								new OracleParameter("P_ISUER", model.ISUER),
								new OracleParameter("P_RETURNID", model.RETURNID)};
  
			for (int i = 0; i < 29; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_feesfree_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_COL_FEESFREE model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_ACTINT", model.ACTINT),
								new OracleParameter("P_ACTMANAGE", model.ACTMANAGE),
								new OracleParameter("P_ACTCAPITAL", model.ACTCAPITAL),
								new OracleParameter("P_LEFTCAPITAL", model.LEFTCAPITAL),
								new OracleParameter("P_ACCPAYDATE", model.ACCPAYDATE),
								new OracleParameter("P_REDCAPITAL", model.REDCAPITAL),
								new OracleParameter("P_REDINT", model.REDINT),
								new OracleParameter("P_REDMANAGE", model.REDMANAGE),
								new OracleParameter("P_REDDELAYINT", model.REDDELAYINT),
								new OracleParameter("P_REDFAILCHARGE", model.REDFAILCHARGE),
								new OracleParameter("P_REDDELAYAMT", model.REDDELAYAMT),
								new OracleParameter("P_REDDONFEE", model.REDDONFEE),
								new OracleParameter("P_REDEXTFEE", model.REDEXTFEE),
								new OracleParameter("P_REDCHARGEFEE", model.REDCHARGEFEE),
								new OracleParameter("P_TOTALREDUCE", model.TOTALREDUCE),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_APPLYBY", model.APPLYBY),
								new OracleParameter("P_APPLYDATE", model.APPLYDATE),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_CANCELBY", model.CANCELBY),
								new OracleParameter("P_CANCELTIME", model.CANCELTIME),
								new OracleParameter("P_CANCELREASON", model.CANCELREASON),
								new OracleParameter("P_TOUSER", model.TOUSER),
								new OracleParameter("P_ISUER", model.ISUER),
								new OracleParameter("P_RETURNID", model.RETURNID)};
  
			for (int i = 0; i < 29; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_feesfree_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_feesfree_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_COL_FEESFREE DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_COL_FEESFREE model = new GSLMS.Entity.TB_COL_FEESFREE();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["LOANID"]!=null && dr["LOANID"].ToString()!="")
				{
					model.LOANID=OracleHelper.ToLong(dr["LOANID"].ToString());
				}
				if(dr["PROID"]!=null && dr["PROID"].ToString()!="")
				{
					model.PROID=OracleHelper.ToLong(dr["PROID"].ToString());
				}
				if(dr["CONID"]!=null && dr["CONID"].ToString()!="")
				{
					model.CONID=OracleHelper.ToLong(dr["CONID"].ToString());
				}
				if(dr["ACTINT"]!=null && dr["ACTINT"].ToString()!="")
				{
					model.ACTINT=OracleHelper.ToDecimal(dr["ACTINT"].ToString());
				}
				if(dr["ACTMANAGE"]!=null && dr["ACTMANAGE"].ToString()!="")
				{
					model.ACTMANAGE=OracleHelper.ToDecimal(dr["ACTMANAGE"].ToString());
				}
				if(dr["ACTCAPITAL"]!=null && dr["ACTCAPITAL"].ToString()!="")
				{
					model.ACTCAPITAL=OracleHelper.ToDecimal(dr["ACTCAPITAL"].ToString());
				}
				if(dr["LEFTCAPITAL"]!=null && dr["LEFTCAPITAL"].ToString()!="")
				{
					model.LEFTCAPITAL=OracleHelper.ToDecimal(dr["LEFTCAPITAL"].ToString());
				}
				if(dr["ACCPAYDATE"]!=null && dr["ACCPAYDATE"].ToString()!="")
				{
					model.ACCPAYDATE=DateTime.Parse(dr["ACCPAYDATE"].ToString());
				}
				if(dr["REDCAPITAL"]!=null && dr["REDCAPITAL"].ToString()!="")
				{
					model.REDCAPITAL=OracleHelper.ToDecimal(dr["REDCAPITAL"].ToString());
				}
				if(dr["REDINT"]!=null && dr["REDINT"].ToString()!="")
				{
					model.REDINT=OracleHelper.ToDecimal(dr["REDINT"].ToString());
				}
				if(dr["REDMANAGE"]!=null && dr["REDMANAGE"].ToString()!="")
				{
					model.REDMANAGE=OracleHelper.ToDecimal(dr["REDMANAGE"].ToString());
				}
				if(dr["REDDELAYINT"]!=null && dr["REDDELAYINT"].ToString()!="")
				{
					model.REDDELAYINT=OracleHelper.ToDecimal(dr["REDDELAYINT"].ToString());
				}
				if(dr["REDFAILCHARGE"]!=null && dr["REDFAILCHARGE"].ToString()!="")
				{
					model.REDFAILCHARGE=OracleHelper.ToDecimal(dr["REDFAILCHARGE"].ToString());
				}
				if(dr["REDDELAYAMT"]!=null && dr["REDDELAYAMT"].ToString()!="")
				{
					model.REDDELAYAMT=OracleHelper.ToDecimal(dr["REDDELAYAMT"].ToString());
				}
				if(dr["REDDONFEE"]!=null && dr["REDDONFEE"].ToString()!="")
				{
					model.REDDONFEE=OracleHelper.ToDecimal(dr["REDDONFEE"].ToString());
				}
				if(dr["REDEXTFEE"]!=null && dr["REDEXTFEE"].ToString()!="")
				{
					model.REDEXTFEE=OracleHelper.ToDecimal(dr["REDEXTFEE"].ToString());
				}
				if(dr["REDCHARGEFEE"]!=null && dr["REDCHARGEFEE"].ToString()!="")
				{
					model.REDCHARGEFEE=OracleHelper.ToDecimal(dr["REDCHARGEFEE"].ToString());
				}
				if(dr["TOTALREDUCE"]!=null && dr["TOTALREDUCE"].ToString()!="")
				{
					model.TOTALREDUCE=OracleHelper.ToDecimal(dr["TOTALREDUCE"].ToString());
				}
				if(dr["REMARK"]!=null && dr["REMARK"].ToString()!="")
				{
					model.REMARK=dr["REMARK"].ToString();
				}
				if(dr["APPLYBY"]!=null && dr["APPLYBY"].ToString()!="")
				{
					model.APPLYBY=dr["APPLYBY"].ToString();
				}
				if(dr["APPLYDATE"]!=null && dr["APPLYDATE"].ToString()!="")
				{
					model.APPLYDATE=DateTime.Parse(dr["APPLYDATE"].ToString());
				}
				if(dr["STATUS"]!=null && dr["STATUS"].ToString()!="")
				{
                    model.STATUS = OracleHelper.ToInt(dr["STATUS"].ToString());
				}
				if(dr["CANCELBY"]!=null && dr["CANCELBY"].ToString()!="")
				{
					model.CANCELBY=dr["CANCELBY"].ToString();
				}
				if(dr["CANCELTIME"]!=null && dr["CANCELTIME"].ToString()!="")
				{
					model.CANCELTIME=DateTime.Parse(dr["CANCELTIME"].ToString());
				}
				if(dr["CANCELREASON"]!=null && dr["CANCELREASON"].ToString()!="")
				{
					model.CANCELREASON=dr["CANCELREASON"].ToString();
				}
				if(dr["TOUSER"]!=null && dr["TOUSER"].ToString()!="")
				{
					model.TOUSER=dr["TOUSER"].ToString();
				}
				if(dr["ISUER"]!=null && dr["ISUER"].ToString()!="")
				{
                    model.ISUER = OracleHelper.ToInt(dr["ISUER"].ToString());
				}
				if(dr["RETURNID"]!=null && dr["RETURNID"].ToString()!="")
				{
					model.RETURNID=OracleHelper.ToLong(dr["RETURNID"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_COL_FEESFREE GetByID(long ID)
		{
			GSLMS.Entity.TB_COL_FEESFREE sModel = new GSLMS.Entity.TB_COL_FEESFREE();
			string sql = "";
			sql = "select * from TB_COL_FEESFREE where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_COL_FEESFREE> GetList(GSLMS.Entity.TB_COL_FEESFREE searchParam)
		{
			var list=new List<GSLMS.Entity.TB_COL_FEESFREE>();
			DataTable dt = null;
			string tblName = "TB_COL_FEESFREE";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_COL_FEESFREE model = new GSLMS.Entity.TB_COL_FEESFREE();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

